package com.example.sqlSession;

import com.example.config.XmlConfigBuilder;
import com.example.pojo.Configuration;

import java.io.InputStream;

/**
 * @author kangshuai
 */
public class SqlSessionFactoryBuilder {


    /**
     * 第一：使用dom4j解析配置文件，将解析出来的内容封装到Configuration中
     * 第二：创建sqlSessionFactory对象：工厂类：生产sqlSession:会话对象
     *
     * @param inputStream
     * @return
     * @throws Exception
     */
    public SqlSessionFactory build(InputStream inputStream) throws Exception {
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);
        return new DefaultSqlSessionFactory(configuration);
    }
}
